package com.sykj.bsc.rwl.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.sykj.bsc.jhy.entity.Bis_nurse_project;
import com.sykj.bsc.rwl.service.SubsrcibeService;
import com.sykj.bsc.rwl.vo.SubsrcibeVo;

/**
 * @ClassName:  SubscribeController   
 *@Description: 预约管理
 * @author 任文龙
 ** @date:   2018年9月6日 上午8:47:27
 */
@Controller
@RequestMapping("proltal/subsrcibe")
public class SubscribeController {
	
	@Autowired
	private SubsrcibeService subsrcibeService;
	
	/**
	 * @Title: selectSubsrcibe   
	 * @Description: 预约管理 显示所有该店铺  
	 * @param: @param shop_id
	 * @param: @param map
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequestMapping("selectSubsrcibe")
	public String selectSubsrcibe(@RequestParam(value="shop_id",required=false)String shop_id,
			HashMap<String,Object> map,HttpServletRequest req) {
		HashMap<String, Object>map2=initMap(req);
		map2.put("shop_id", shop_id);
		List<Map<String,Object>> listMap=subsrcibeService.selectSubsrcibe(map2);
		map.put("listMap", listMap);
		map.put("shop_id", shop_id);
		return "foreground/subscribe";
	}
	
	private HashMap<String,Object> initMap(HttpServletRequest req){
		String order_id=req.getParameter("order_id");
		String mobile=req.getParameter("mobile");
		String username=req.getParameter("username");
		String subscribe_time=req.getParameter("subscribe_time");
		HashMap<String, Object> map=new HashMap<>();
		if(order_id!=null && !order_id.equals("")) {
			map.put("order_id", order_id);
			req.setAttribute("order_id", order_id);
		}
		if(mobile!=null && !mobile.equals("")) {
			map.put("mobile", mobile);
			req.setAttribute("mobile", mobile);
		}
		if(username!=null && !username.equals("")) {
			map.put("username", username);
			req.setAttribute("username", username);
		}
		if(subscribe_time!=null && !subscribe_time.equals("")) {
			map.put("subscribe_time", subscribe_time);
			req.setAttribute("subscribe_time", subscribe_time);
		}
		return map;
	}
	
	
	/**
	 * @Title: saveSubsrcibe   
	 * @Description: 添加  
	 * @param: @param subsrcibeVo
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequestMapping("saveSubsrcibe")
	public String saveSubsrcibe(SubsrcibeVo subsrcibeVo) {
		subsrcibeService.saveSubsrcibe(subsrcibeVo);
		return "redirect:selectSubsrcibe?shop_id="+subsrcibeVo.getShop_id();
	}
	
	/**
	 * @Title: selectNurseProject   
	 * @Description: 显示所有的项目   
	 * @param: @param map
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequestMapping("selectNurseProject")
	public String selectNurseProject(Map<String,Object> map,@RequestParam(value="shop_id",required=false)String shop_id) {
		List<Map<String,Object>> listMap=subsrcibeService.selectNurseProject();
		map.put("listMap", listMap);
		map.put("shop_id", shop_id);
		System.out.println(shop_id);
		return "foreground/nurseProject";
	}
	
	/**
	 * @Title: checkProject   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param 通过id查询该项目
	 * @param: @param model
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequestMapping("checkProject")
	public String checkProject(@RequestParam(value="project_id")String project_id,
			@RequestParam(value="shop_id",required=false)String shop_id,Model model) {
		Bis_nurse_project b=subsrcibeService.checkProject(project_id);
		model.addAttribute("b", b);
		model.addAttribute("shop_id", shop_id);
		return "foreground/saveSubsrcibe";
	}
	
	/**
	 * @Title: checkCustomName   
	 * @Description: 判断客户是否存在  
	 * @param: @param mobile
	 * @param: @param map
	 * @param: @param resp      
	 * @return: void      
	 * @throws
	 */
	@RequestMapping("checkCustomName")
	public void checkCustomName(String mobile,HashMap<String,Boolean> map,HttpServletResponse resp){
		boolean bool=subsrcibeService.selectCustom(mobile);
		map.put("valid", bool);
		SysUserController.getWirte(resp, map);
	}
	
	@RequestMapping("saveSubsrcibeProject")
	public String saveSubsrcibe(String shop_id,Model model) {
		model.addAttribute("shop_id", shop_id);
		return "foreground/saveSubsrcibe";
	}
}